#include <stdio.h>
#include <string.h>
#include <ctype.h>

void convertPassword(char *password) {
    for (int i = 0; password[i]!= '\0'; i++) {
        if (islower(password[i])) {
            password[i] = toupper(password[i]);
        } else if (isupper(password[i])) {
            password[i] = tolower(password[i]);
        }
    }
}

int main() {
    char phoneNumber[51];
    scanf("%s", phoneNumber);
    int n;
    scanf("%d", &n);
    int found = 0;
    for (int i = 0; i < n; i++) {
        char username[51], password[51], phone[51];
        scanf("%s %s %s", username, password, phone);
        if (strcmp(phone, phoneNumber) == 0) {
            found = 1;
            convertPassword(password);
            printf("%s %s\n", username, password);
        }
    }
    if (!found) {
        printf("empty");
    }
    return 0;
}
